package yz;

/**
 * [面试题 01.08. 零矩阵](https://leetcode-cn.com/problems/zero-matrix-lcci/)
 *
 * @author Yz
 * @since 2022-09-17 16:39
 */
public class LeetCode0108_ZeroMatrix {
    public void setZeroes(int[][] matrix) {
        boolean[] rows = new boolean[matrix.length];
        boolean[] cols = new boolean[matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 0) {
                    rows[i] = true;
                    cols[j] = true;
                }
            }
        }
        for (int i = 0; i < rows.length; i++) {
            if (rows[i]) {
                for (int k = 0; k < matrix[0].length; k++) {
                    matrix[i][k] = 0;
                }
            }
        }
        for (int i = 0; i < cols.length; i++) {
            if (cols[i]) {
                for (int k = 0; k < matrix.length; k++) {
                    matrix[k][i] = 0;
                }
            }
        }
    }
}
